﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace NETCORE.ConSul.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class BookController : ControllerBase
    {

        IHttpClientFactory _clientFactory;
        public BookController(IHttpClientFactory clientFactory)
        {
            _clientFactory = clientFactory;
        }

        [Route("CallPen")]
        [HttpPost]
        public async Task<IActionResult> CallPen()
        {
            var client = _clientFactory.CreateClient("ServiceService1");//必须与startup里面注入的名称对应
            //var content = new StringContent("");
            //content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            var response = await client.GetAsync("api/pen/GetPenInfo");
            var sss = response.Content.ReadAsStringAsync().Result; 
            return Ok(sss); 
        }



        [Route("GetInfo")]
        [HttpGet]
        public IActionResult GetInfo()
        {
            Task.Run(() => { Console.WriteLine("name:onn , Host:{0}", HttpContext.Request.Host.Value); });
            return Ok("ok , task running go !");
        }


    }
}
